namespace DotNetNuke.Services.Scheduling
{
    using DotNetNuke.Common.Utilities;
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;

    public class ScheduleItem
    {
        private string _AttachToEvent = Null.NullString;
        private bool _CatchUpEnabled = Null.NullBoolean;
        private bool _Enabled = Null.NullBoolean;
        private DateTime _NextStart = Null.NullDate;
        private string _ObjectDependencies = Null.NullString;
        private int _ProcessGroup = Null.NullInteger;
        private int _RetainHistoryNum = Null.NullInteger;
        private int _RetryTimeLapse = Null.NullInteger;
        private string _RetryTimeLapseMeasurement = Null.NullString;
        private int _ScheduleID = Null.NullInteger;
        private Hashtable _ScheduleItemSettings;
        private DotNetNuke.Services.Scheduling.ScheduleSource _ScheduleSource;
        private string _Servers = Null.NullString;
        private int _ThreadID = Null.NullInteger;
        private int _TimeLapse = Null.NullInteger;
        private string _TimeLapseMeasurement = Null.NullString;
        private string _TypeFullName = Null.NullString;

        public void AddSetting(string Key, string Value)
        {
            this._ScheduleItemSettings.Add(Key, Value);
        }

        public string GetSetting(string Key)
        {
            if (this._ScheduleItemSettings == null)
            {
                this.GetSettings();
            }
            if (this._ScheduleItemSettings.ContainsKey(Key))
            {
                return Convert.ToString(RuntimeHelpers.GetObjectValue(this._ScheduleItemSettings[Key]));
            }
            return "";
        }

        public Hashtable GetSettings()
        {
            this._ScheduleItemSettings = SchedulingProvider.Instance().GetScheduleItemSettings(this.ScheduleID);
            return this._ScheduleItemSettings;
        }

        public bool HasObjectDependencies(string strObjectDependencies)
        {
            if (strObjectDependencies.IndexOf(",") > -1)
            {
                string[] a = Strings.Split(strObjectDependencies.ToLower(), ",", -1, CompareMethod.Binary);
                int refIntHelperL0 = a.Length - 1;
                for (int i = 0; i <= refIntHelperL0; i++)
                {
                    if (a[i] == strObjectDependencies.ToLower())
                    {
                        return true;
                    }
                }
            }
            else if (this.ObjectDependencies.ToLower().IndexOf(strObjectDependencies.ToLower()) > -1)
            {
                return true;
            }
            return false;
        }

        public string AttachToEvent
        {
            get
            {
                return this._AttachToEvent;
            }
            set
            {
                this._AttachToEvent = value;
            }
        }

        public bool CatchUpEnabled
        {
            get
            {
                return this._CatchUpEnabled;
            }
            set
            {
                this._CatchUpEnabled = value;
            }
        }

        public bool Enabled
        {
            get
            {
                return this._Enabled;
            }
            set
            {
                this._Enabled = value;
            }
        }

        public DateTime NextStart
        {
            get
            {
                if (DateTime.Compare(this._NextStart, Null.NullDate) == 0)
                {
                    this._NextStart = DateAndTime.Now;
                }
                return this._NextStart;
            }
            set
            {
                this._NextStart = value;
            }
        }

        public string ObjectDependencies
        {
            get
            {
                return this._ObjectDependencies;
            }
            set
            {
                this._ObjectDependencies = value;
            }
        }

        public int ProcessGroup
        {
            get
            {
                return this._ProcessGroup;
            }
            set
            {
                this._ProcessGroup = value;
            }
        }

        public int RetainHistoryNum
        {
            get
            {
                return this._RetainHistoryNum;
            }
            set
            {
                this._RetainHistoryNum = value;
            }
        }

        public int RetryTimeLapse
        {
            get
            {
                return this._RetryTimeLapse;
            }
            set
            {
                this._RetryTimeLapse = value;
            }
        }

        public string RetryTimeLapseMeasurement
        {
            get
            {
                return this._RetryTimeLapseMeasurement;
            }
            set
            {
                this._RetryTimeLapseMeasurement = value;
            }
        }

        public int ScheduleID
        {
            get
            {
                return this._ScheduleID;
            }
            set
            {
                this._ScheduleID = value;
            }
        }

        public DotNetNuke.Services.Scheduling.ScheduleSource ScheduleSource
        {
            get
            {
                return this._ScheduleSource;
            }
            set
            {
                this._ScheduleSource = value;
            }
        }

        public string Servers
        {
            get
            {
                return this._Servers;
            }
            set
            {
                value = Strings.Trim(value);
                if (value.Length > 0)
                {
                    if (value.IndexOf(",") > 0)
                    {
                        value = "," + value;
                    }
                    if (value.LastIndexOf(",") < (value.Length - 1))
                    {
                        value = value + ",";
                    }
                }
                this._Servers = value;
            }
        }

        public int ThreadID
        {
            get
            {
                return this._ThreadID;
            }
            set
            {
                this._ThreadID = value;
            }
        }

        public int TimeLapse
        {
            get
            {
                return this._TimeLapse;
            }
            set
            {
                this._TimeLapse = value;
            }
        }

        public string TimeLapseMeasurement
        {
            get
            {
                return this._TimeLapseMeasurement;
            }
            set
            {
                this._TimeLapseMeasurement = value;
            }
        }

        public string TypeFullName
        {
            get
            {
                return this._TypeFullName;
            }
            set
            {
                this._TypeFullName = value;
            }
        }
    }
}

